package com.tcd.customer.contrller;

import com.tcd.customer.service.RecognizeeInfoService;
import com.tcd.customer.service.PolicyholdersInfoService;

import com.tcd.pojo.Client.PolicyholdersInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/policyholdersInfoController")
public class PolicyholdersInfoController {
    @Autowired
    PolicyholdersInfoService policyholdersInfoService;
    @Autowired
    RecognizeeInfoService recognizeeInfoService;

    @RequestMapping("/getAll")
    public List<PolicyholdersInfo> getAll(){
        List<PolicyholdersInfo> list= policyholdersInfoService.getAll();
        System.out.println(list);
        return list;
    }

    @RequestMapping("/query")
    public List<PolicyholdersInfo> query(String policyholdersName, String policyholdersId){
        System.out.println(policyholdersName);
        System.out.println(policyholdersId);
        List<PolicyholdersInfo> list= policyholdersInfoService.query(policyholdersName,policyholdersId);
        System.out.println(list);
        return list;
    }

    @RequestMapping("/addPolicyholdersInfo")
    public int addPolicyholdersInfo(PolicyholdersInfo policyholdersInfo){
        System.out.println(policyholdersInfo);
        int row=policyholdersInfoService.addPolicyholdersInfo(policyholdersInfo);
        return row;
    }

    @RequestMapping("/deleteRow")
    public int deleteRow(int policyholdersId){
        int row=policyholdersInfoService.deleteRow(policyholdersId);
        return row;
    }
    @RequestMapping("/deleteAll")
    public int deleteAll(int policyholdersId){
        System.out.println(policyholdersId);
//        List<RecognizeeInfo> list=recognizeeInfoService.getAll();
//        for (int i=0;i<list.size();i++){
//            RecognizeeInfo r=list.get(i);
//            int pd=r.getPolicyholdersId();
//            if(pd==policyholdersId){
//                int row=recognizeeInfoService.deleteRow(policyholdersId);
//                System.out.println(row);
//                if(row>0)
//                    System.out.println("成功");
//            }
//        }
        int row1=recognizeeInfoService.deleteRow(policyholdersId);
        System.out.println(row1);
        int row=policyholdersInfoService.deleteRow(policyholdersId);
        return row;
    }


    @RequestMapping("/amendRow")
    public int amendRow(PolicyholdersInfo policyholdersInfo){
        System.out.println(policyholdersInfo);
        int row=policyholdersInfoService.amendRow(policyholdersInfo);
        return row;
    }

    @RequestMapping("/getpolicyholdersName")
    public List<PolicyholdersInfo> getpolicyholdersName(){
        return policyholdersInfoService.getpolicyholdersName();
    }

}
